package com.mccrea.pattern.expression;

/**
 * @Classname Context
 * @Description 环境类
 * @Date 2021/5/24 0024 14:34
 * @Created by Mccrea_Gao
 */
public class Context {
    private String[] citys = {"合肥", "池州"};
    private String[] persons = {"老人", "妇女", "儿童"};
    private AbstractExpression expression;

    public Context() {
        expression = new NonTerminalExpression(new TerminalExpression(citys), new TerminalExpression(persons));
    }

    public void freeRides(String info) {
        boolean interpret = expression.interpret(info);
        if (interpret) {
            System.out.println(info + " ：免费乘车");
        } else {
            System.out.println(info + " ：不能免费乘车");
        }
    }
}
